var HtmlObj = {
	getScrollTop:function (){
		return document.documentElement.scrollTop||document.body.scrollTop;//ie,ff||webkit
	},
	getScrollLeft:function(){
		return document.documentElement.scrollLeft||document.body.scrollLeft;
	},
	//(clientLeft,clientTop)这两个返回的是元素周围边框的厚度,如果不指定一个边框或者不定位改元素,他的值就是0
	getMousePos:function(ev){
		if(ev.pageX||ev.pageY){//ff pecuiliar , [ offsetX(IE) , layerX(ff) 需要position才能使用， 不推荐使用]
			return {x:ev.pageX,y:ev.pageY};
		} else if(document.documentElement&&document.documentElement.scrollTop){//ie
			return{
				x:ev.clientX+document.documentElement.scrollLeft-document.documentElement.clientLeft,
				y:ev.clientY+document.documentElement.scrollTop-document.documentElement.clientTop
			};
		}else if(document.body){
			return{
				x:ev.clientX+document.body.scrollLeft-document.body.clientLeft,
				y:ex.clientY+document.body.scrollTop-document.body.clientTop
			};
		}
	},
	getItself:function(id){
		return "string"== typeof id?document.getElementById(id):id;
	},
	//(offsetWidth,offsetHeight)包括边线的宽
	getViewPortSize:function(){
		var p = {};
		if(window.innerWidth){// not ie
			p.w = window.innerWidth;
			p.h = window.innerHeight;
		} else if(document.documentElement&&document.documentElement.clientWidth){
			p.w = document.documentElement.clientWidth;
			p.h = document.documentElement.clientHeight;
		} else {
			p.w = document.body.offsetWidth;
			p.h = document.body.offsetHeight;
		}
	}
};

//string range substring
String.prototype.rangeSubstring = function (limit){
	var string = this;
	if(string.constructor==String&&limit.constructor==Number){
		var obj = {};
		obj.string = string;
		obj.flag = true;
		var len  = obj.len = string.length;
		if(len>limit) {
			obj.string = string.substring(0,limit);
			obj.flag = false;
			obj.len = limit;
		} 
		return obj;
	}
	return "data type no match";
};
//去掉重复array值
Array.prototype.delRepeat=function(){
    var newArray=[];
    var provisionalTable = {};
    for (var i = 0,item;(item= this[i])!=null;i++) {
        if (!provisionalTable[item]) {
            newArray.push(item);
            provisionalTable[item] = true;
        }
    }
    return newArray;
}
//time
function fnTimeCounter(time,curTime,format){
	var defaultFormat = "yyyy-MM-dd HH:mm:ss";
	if(!format) format = defaultFormat;
	var pubTime = fnListTimeFormat.fnStringToDate(time,format);
	var endTime = fnListTimeFormat.fnStringToDate(curTime,format);
	var mmlen1 = pubTime.getTime();//1970-到现在的分钟差(返回 1970 年 1 月 1 日至今的毫秒数。)
	var mmlen2 = endTime.getTime();//1970-到现在的分钟差  getTimezoneOffset()
	var interzone = (mmlen2-mmlen1)/(1000*60);
	if(interzone<60){
		return interzone+"分钟前";
	} else if(interzone<60*24){
		return parseInt(interzone/60,10)+"小时前";
	} else if(interzone<60*24*30){
		return parseInt((interzone/(60*24)),10)+"天前";
	} else if(interzone<60*24*30*12){
		return parseInt((interzone/(60*24*30)),10)+"月前";
	} else if(interzone>60*24*30*12){
		return parseInt((interzone/(60*24*30*12)),10)+"年前";
	}
}
function fnRatio(obj,ltFlag){
	var defaultW = obj.defaultW,defaultH = obj.defaultH;
	var imgW = obj.imgW,imgH = obj.imgH;
	var mt = 0,ml = 0;
	if(ltFlag===false){
		if(imgW>defaultW&&imgH>defaultH){
			if(imgW/defaultW>imgH/defaultH){
				imgH = imgH/(imgW/defaultW);
				imgW = defaultW;
			} else {
				imgW = imgW/(imgH/defaultH);
				imgH = defaultH;
			}
		} else if(imgW>defaultW){
			imgH = imgH/(imgW/defaultW);
			imgW = defaultW;
		} else if(imgH>defaultH){
			imgW = imgW/(imgH/defaultH);
			imgH = defaultH;
		}
	} else if(imgW&&imgH){
		if(imgW>defaultW&&imgH>defaultH){
			mt = (imgH-defaultH)/2;
			ml = (imgW-defaultW)/2;
		} else if(imgW>defaultW&&imgH<defaultH){
			imgW = (defaultH/imgH)*imgW;
			imgH = defaultH;
			ml = (imgW-defaultW)/2;
		} else if(imgW<defaultW&&imgH>defaultH){
			imgH = (defaultW/imgW)*imgH;
			imgW = defaultW;
			mt = (imgH-defaultH)/2;
		} else {
			var flag = defaultW/imgW>defaultH/imgH?true:false;
			if(flag){
				imgH = (defaultW/imgW)*imgH;
				imgW = defaultW;
				mt = (imgH-defaultH)/2;
			} else {
				imgW = (defaultH/imgH)*imgW;
				imgH = defaultH;
				ml = (imgW-defaultW)/2;
			}
		}
	}
	return {imgW:imgW,imgH:imgH,mt:mt,ml:ml};
}
function replaceHttpToATag(string,split){
	var arr = [];
	var temp = string;
	while(true){
		var index = temp.indexOf("http");
		if(index>=0){
			arr.push(temp.substring(0,index));
			temp = temp.substring(index);
			var index2 = temp.indexOf(split);
			if(index2==-1)index2 = temp.length;
			var url = temp.substring(0,index2);
			arr.push("<a href='"+url+"'>"+url+"<a>");
			temp = temp.substring(index2);
		} else {
			arr.push(temp);
			break;
		}
	}
	return arr.join("");
}
String.prototype.lenReg = function(){
	return this.replace(/[^x00-xFF]/g,'**').length;
};

function isFull(pChar){
	for (var i=0;i<pChar.strLen;i++) {
		if((pChar.charCodeAt(i)>128))return true;
		else return false;
	}
}

function autoAddEllipsis(pStr, pLen){
	var _ret = cutString(pStr, pLen);  
    var _cutFlag = _ret.cutflag;  
    var _cutStringn = _ret.cutstring;  
    if ("1"==_cutFlag) return _cutStringn + "...";  
    else return _cutStringn;
}
function cutString(pStr, pLen) {
	var _strLen = pStr.length;  
    var _tmpCode;  
    var _cutString;
    var _cutFlag = "1";  
    var _lenCount = 0;  
    var _ret = false;
    if (_strLen <= pLen/2){_cutString = pStr;_ret = true;}
   	if (!_ret){
   		for (var i=0;i<_strLen;i++){ 
   			if (isFull(pStr.charAt(i)))_lenCount+=2;
   			else _lenCount+=1;
   			 if (_lenCount>pLen){
   			 	_cutString = pStr.substring(0,i);
   			 	_ret = true;  
                break;
   			 }else if(_lenCount==pLen){
   			 	_cutString = pStr.substring(0,i+1);  
                _ret = true;  
                break;
   			 }
   		}	
   	}
   	if(!_ret){_cutString=pStr;_ret = true;}
   	if(_cutString.length==_strLen) _cutFlag = "0";
   	return {"cutstring":_cutString, "cutflag":_cutFlag}; 
}


